var gulp = require('gulp'),
	livereload = require('gulp-livereload'),
	webserver = require('gulp-webserver'),//加载模块
 	sass = require('gulp-ruby-sass'),
 	uglify = require('gulp-uglify');
 	// imagemin = require('gulp-imagemin');//图片压缩
//注册html任务
gulp.task('html',()=>{
	return gulp.src('project/html/*.html')//指明文件路径  /**/监听目录下所有的.html文件
    .pipe(gulp.dest('project/dist/html'));//输出路径
});
//注册任务
gulp.task('webserver',()=>{
	gulp.src('project').pipe(webserver({
		livereload:true,
		open:true
	}));
});

//注册css任务
gulp.task('sass',function(){
	return sass('project/css/*.scss',{style:'compressed'})
	.pipe(gulp.dest('project/dist/css'))
})

//注册js任务
gulp.task('myjs',()=>{
	return gulp.src('project/js/*.js')
	.pipe(uglify({ preserveComments:'some'}))//保留注释压缩
	.pipe(gulp.dest('project/dist/js')); 
});

gulp.task('css',()=>{
	return gulp.src('project/css/*.css')
	.pipe(gulp.dest('project/dist/css')); 
});
//监听任务
gulp.task('watch',function(){
	gulp.watch('project/html/*.html',['html']);
	gulp.watch('project/css/*.scss',['sass']);////监听目录下所有的.html文件
});
//默认任务
gulp.task('default',['sass','html','myjs','webserver','watch']);
